package com.serkol.driving.learning.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.serkol.driving.learning.entity.ExamResult;
import com.serkol.driving.learning.mapper.ExamResultMapper;
import com.serkol.driving.learning.service.ExamResultService;
import com.serkol.driving.learning.utils.SwitchUtil;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
* @author pingan
* @description 针对表【exam_result】的数据库操作Service实现
* @createDate 2022-08-01 16:39:16
*/
@Service
public class ExamResultServiceImpl extends ServiceImpl<ExamResultMapper, ExamResult>
    implements ExamResultService{


    @Override
    public List<Integer> getStastica() {
        LambdaQueryWrapper<ExamResult> queryWrapper=new LambdaQueryWrapper<ExamResult>();

        queryWrapper.select(ExamResult::getIntegral).orderByDesc(ExamResult::getId).last("LIMIT 10");

        List<Object> objects =this.baseMapper.selectObjs(queryWrapper);
        List<Integer> integers = SwitchUtil.objToList(objects, Integer.class);


        return integers;
    }

    @Override
    public List<Map<String, Object>> getUsersStastica() {
     QueryWrapper<ExamResult> queryWrapper=new QueryWrapper<ExamResult>();


        queryWrapper.lambda().groupBy(ExamResult::getUserId).orderByDesc(ExamResult::getId,ExamResult::getIntegral).last("LIMIT 50");
        List<Map<String, Object>> maps = this.baseMapper.getUsersStastica(queryWrapper);
        return maps;
    }
}




